package com.hamster.crmpre.web;

import com.hamster.crmpre.pojo.Customer;
import com.hamster.crmpre.pojo.CustomerVip;
import com.hamster.crmpre.pojo.Project;
import com.hamster.crmpre.service.CustomerVipService;
import com.hamster.crmpre.service.ProjectService;
import com.hamster.crmpre.pojo.CustomerRecord;
import com.hamster.crmpre.service.ProjectBuyService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 手机端： 购买项目的Controller
 * @author Tarry
 * @create 2019/12/24 16:08
 */
@RestController
@RequestMapping("project")
public class ProjectBuyController {
    @Autowired
    private ProjectService projectService; //后台module的Service
    @Autowired
    private ProjectBuyService projectBuyService;
    @Autowired
    private CustomerVipService customerVipService;
    /**
     * 购买项目页面的项目下拉框列表
     * @return
     */
    @GetMapping("listOption")
    public ResponseEntity<List<Project>> listOptions(){
        List<Project> projects = projectService.listOptions();
        return ResponseEntity.ok(projects);
    }

    /**
     * 购买项目
     * @return
     */
    @PostMapping("buy")
    public ResponseEntity<Void> insert(@RequestBody CustomerRecord customerRecord){
        projectBuyService.insert(customerRecord);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据手机号查询推荐人
     * @param phone
     * @return
     */
    @GetMapping("getRecommend")
    public ResponseEntity<Customer> queryCustomerByPhone(@RequestParam String phone){
        Customer customer = projectBuyService.queryCustomerByPhone(phone);
        return ResponseEntity.ok(customer);
    }

    /**
     * 获取推荐人 select 【vip，合伙人】
     * @return
     */
    @GetMapping("querySelect")
    public ResponseEntity<List<CustomerVip>> querySelect(){
        List<CustomerVip> list = customerVipService.querySelect();
        return ResponseEntity.ok(list);
    }


}
